package com.demo.nio.client;

import java.io.*;
import java.net.Socket;

/**
 * Created by hunter
 *
 * @Description 阻塞IO实现的客户端
 */
public class Client {

    private static final int PORT = 8000;

    private Socket socket;

    private String name;

    public void startClient() throws IOException {
        socket = new Socket("localhost", PORT);
    }

    public void sendMessage(String message) throws IOException {
        socket.getOutputStream().write((this.name + " : " + message).getBytes());
        socket.getOutputStream().flush();
    }

    public Client(String name) {
        this.name = name;
    }
}
